<template>
	<view class="customerManagement">
		<input type="text" v-model="val" @input="searchVal" :placeholder="icon" confirm-type="search" />

		<view class="lists" v-for="(item,index) in list" @click="jumpCustomerDetails(index)">
			<view class="img">
				<image :src="item.avatar_url" mode="scaleToFill" style="width: 100rpx; height: 100rpx;"></image>
			</view>
			<view class="info">
				<text>{{item.user_name}}</text>
				<text v-if="item.user_sex == 1" class="gender">男</text>
				<text class="gender" v-else>女</text>
				<text class="age">{{item.user_age}}岁</text>
				<text>预约次数:<text class="numbers">{{item.sub_num}}</text></text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getCustomer();
		},
		data() {
			return {
				icon: '搜索关键字',
				val: "",
				list: null,
			};
		},
		methods: {
			jumpHomePage() {
				uni.navigateTo({
					url: "../../homePage3/homePage3"
				})
			},
			async searchVal() {
				let id = this.$store.state.userinfo.id;
				let keyword = this.val;
				let res = await this.$myrequest({
					url: `Service/getCustomer?id=${id}&keyword=${keyword}`
				});
				this.list = res.data.data;
			},

			jumpCustomerDetails(index) {
				let datas = this.list.filter((value, key, arr) => {
					if (index == key) {
						return value;
					};
				});
				uni.navigateTo({
					url: `../customerDetails2/customerDetails2?datas=${encodeURIComponent(JSON.stringify(datas[0]))}`
				})
			},
			async getCustomer() {
				let id = this.$store.state.userinfo.id;
				let res = await this.$myrequest({
					url: `Service/getCustomer?id=${id}`
				});
				this.list = res.data.data;
			},
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background-color: #F1F3F4;
	}

	.customerManagement {
		width: 100%;
		height: 100%;
		padding: 0 30rpx;
		background-color: #F1F3F4;

		input {
			margin: 20rpx auto 10rpx;
			width: 690rpx;
			height: 60rpx;
			text-align: center;
			color: #969799;
			font-size: 30rpx;
			background-color: #FFFFFF;
			border-radius: 30px;
		}
	}

	.lists {
		display: flex;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;

		.img {
			width: 100rpx;
			height: 100rpx;
			display: flex;
			justify-content: center;
			margin-right: 25rpx;

			image {
				border-radius: 50%;
			}
		}
	}

	.info {
		display: flex;
		height: 100rpx;
		width: 100%;
		align-items: center;

		>text {
			display: inline-block;

			&:first-of-type {
				width: 120rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: rgba(55, 52, 56, 1);
			}

			&:nth-of-type(2),
			&:nth-of-type(3) {
				color: #7D7E80;
			}

			&:nth-of-type(3) {
				margin-left: 30rpx;
			}

			&:last-of-type {
				color: #373438;
				font-size: 26rpx;
				margin-left: 100rpx;

				text {
					color: #2DD1BC;
					margin-left: 20rpx;
				}
			}
		}
	}
</style>
